package com.jasonzhou.onetomanycontrol.room

import com.jasonzhou.onetomanycontrol.room.entity.AdjustColor
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class AdjustColorRepository(private val adjustColorDao: AdjustColorDao) {
    suspend fun insertColor(vararg adjustColor: AdjustColor): List<Long> {
        return withContext(Dispatchers.IO) {
            adjustColorDao.insertAll(*adjustColor)
        }
    }

    suspend fun findColorByColorAndBright(type: Int,color: Int, bright: Int): AdjustColor? {
        return withContext(Dispatchers.IO) {
            adjustColorDao.findColorByColorAndBright(type,color, bright)
        }
    }

    suspend fun delColor(id: Long) {
        withContext(Dispatchers.IO) {
            adjustColorDao.delColor(id)
        }
    }

    suspend fun updateColor(adjustColor: AdjustColor) {
        withContext(Dispatchers.IO) {
            adjustColorDao.updateColor(adjustColor)
        }
    }

    suspend fun getAllColor(): List<AdjustColor> {
        return withContext(Dispatchers.IO) {
            adjustColorDao.getAllColor()
        }
    }

    suspend fun getAllWhite(): List<AdjustColor> {
        return withContext(Dispatchers.IO) {
            adjustColorDao.getAllWhite()
        }
    }


}